//
//  KZLoginViewController.m
//  xiaorizi
//
//  Created by kun on 15/10/29.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZLoginViewController.h"
#import "WXApiRequestHandler.h"
#import "WXApiManager.h"
#import "AppDelegate.h"
#import "WeiboUser.h"



typedef NS_ENUM(NSUInteger, LoginCategory) {
    WXLOGIN,
    QQLOGIN,
    WBLOGIN,
};


@interface KZLoginViewController ()<WXApiManagerDelegate,TencentSessionDelegate>
@property (weak, nonatomic) IBOutlet UIImageView *weiboLogin;
@property (weak, nonatomic) IBOutlet UIImageView *weixinLogin;
@property (weak, nonatomic) IBOutlet UIImageView *qqLogin;


@property (nonatomic,assign) LoginCategory LoginAppCategory;

@end

@implementation KZLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //1 添加微博事件
    _weiboLogin.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedWeiboView:)];
    [self.weiboLogin addGestureRecognizer:tap];
    
    //2: QQ登陆
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedQqView:)];
    _qqLogin.userInteractionEnabled = YES;
    [self.qqLogin  addGestureRecognizer:tap1];
    
    
    //3 微信登陆
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickedWxView:)];
    _weixinLogin.userInteractionEnabled = YES;
    [self.weixinLogin addGestureRecognizer:tap2];
}

- (void)clickedWeiboView:(UITapGestureRecognizer *)tap
{
    NSLog(@"------>微博登陆");

    WBAuthorizeRequest *request = [WBAuthorizeRequest request];
    request.redirectURI = kRedirectURI;
    request.scope = @"all";
    request.userInfo = @{@"SSO_From": @"SendMessageToWeiboViewController",
                         @"Other_Info_1": [NSNumber numberWithInt:88888],
                         @"Other_Info_2": @[@"obj1", @"obj2"],
                         @"Other_Info_3": @{@"key1": @"obj1", @"key2": @"obj2"}};
    [WeiboSDK sendRequest:request];
    

}

//qq 代理实现
-(void)clickedQqView:(UITapGestureRecognizer *)tap
{
    //_labelTitle.text = @"开始获取token";
    NSString *appid = @"222222";
    
    TencentOAuth* _tencentOAuth = [[TencentOAuth alloc] initWithAppId:appid
                                            andDelegate:self];
    
    NSArray * _permissions =  [NSArray arrayWithObjects:@"get_user_info", @"get_simple_userinfo", @"add_t", nil];

    [_tencentOAuth authorize:_permissions inSafari:NO];
}


-(void)clickedWxView:(UITapGestureRecognizer *)tap
{

   [WXApiRequestHandler sendAuthRequestScope: kAuthScope
                                            State:kAuthState
                                           OpenID:kAuthOpenID
                                 InViewController:self];
}


//qq登陆 提示
- (void)tencentDidLogin
{
    NSLog(@"--->登陆成功");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}








/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
